******************
*Thorin M. Wright and Paul F. Diehl
*"Unpacking Territorial Disputes: Domestic Political Influences and War"
*Journal of Conflict Resolution
*Replication Script for main article and web appendix
******************
*Notes on the data:
*The Senese and Vasquez data used for the Interactions Chapter of "Steps to War" (2008) serves as the MID data for this article
*The dyad variable this data uses is non-directional, as are the dispute observations themselves (there is only one observation per dyad-dispute number), 
*but ccode1 and ccode2 variables are set up as side a and side b.

*The analyses are split between an analysis of the 1816-2001 period and the 1946-1999 period, utilizing Jessica Weeks' (2012) replication data
*In order to make the data as clear and user-friendly as possible, we have split the analysis such that the first dataset used is the 1816-2001 
*for our initial hypotheses, following those are the analyses using the Weeks data that covers only 1946-1999.


clear
set more off

*Set working directory to the folder where the user has the file 
cd ""

use "Wright_Diehl_2014_JCR_1816-2001.dta"


**Table 1

**descriptive breakdown of territorial MIDs and war within 5 years

tab mixed cow5yrwi if territor==1 & terrXmixed !=. & territor !=. &  terrXdem !=. &  jtdem !=. &  caprat !=. &  terrcount !=. &  rival !=., expected row chi2

tab jtauto cow5yrwi if territor==1 & terrXmixed !=. & territor !=. &  terrXdem !=. &  jtdem !=. &  caprat !=. &  terrcount !=. &  rival !=., expected row chi2

tab jtdem cow5yrwi if territor==1 & terrXmixed !=. & territor !=. &  terrXdem !=. &  jtdem !=. &  caprat !=. &  terrcount !=. &  rival !=., expected row chi2


*Table 2
logit cow5yrwi mixed terrXmixed territor  jtdem caprat terrcount rival 

logit cow5yrwi mixed terrXmixed territor jtdem caprat terrcount  if rival==1

logit cowwar mixed terrXmixed territor  jtdem caprat terrcount  rival

logit cowwar mixed terrXmixed territor  jtdem caprat terrcount  if rival==1




*Figure 1 Probabilities (and First Differences, Figure 1 in Appendix)


estsimp logit cow5yrwi mixed terrXmixed territor jtdem caprat terrcount if rival==1

*base (non-territorial, jtauto)
setx mixed 0 territor 0 terrXmixed 0  jtdem 0 caprat (mean) terrcount (mean)
simqi, pr level(90)


*territorial, mixed
setx mixed 1 territor 1 terrXmixed 1 jtdem 0 caprat (mean)  terrcount (mean)
simqi, pr level(90)

*territorial, jtauto
setx mixed 0 territor 1 terrXmixed 0 jtdem 0 caprat (mean)  terrcount (mean)
simqi, pr level(90)

*non-territorial, mixed
setx mixed 1 territor 0 terrXmixed 0 jtdem 0 caprat (mean)  terrcount (mean)
simqi, pr level(90)

*non-territorial jtdem
setx mixed 0 territor 0 terrXmixed 0 jtdem 1 caprat (mean) terrcount (mean)
simqi, pr level(90)


*first differences in probablity of war in 5 years. 
setx mixed 0 territor 0 terrXmixed 0 jtdem 0 caprat (mean) terrcount (mean)
simqi, fd(prval(1))  changex(territor 0 1) level(90)

setx mixed 0 territor 1 terrXmixed 0 jtdem 0 caprat (mean) terrcount (mean)
simqi, fd(prval(1))  changex(terrXmixed 0 1  mixed 0 1) level(90)

setx mixed 1 territor 0 terrXmixed 0 jtdem 0 caprat (mean) terrcount (mean)
simqi, fd(prval(1))  changex(terrXmixed 0 1  territor 0 1) level(90)

setx mixed 0 territor 0 terrXmixed 0 jtdem 0 caprat (mean) terrcount (mean)
simqi, fd(prval(1))  changex(jtdem 0 1) level(90)

setx mixed 0 territor 0 terrXmixed 0 jtdem 0 caprat (mean) terrcount (mean)
simqi, fd(prval(1))  changex(territor 0 1 terrXmixed 0 1 mixed 0 1) level(90)

drop b1 b2 b3 b4 b5 b6 b7 



*Appendix Table 1

logit cow5yrwi mixed caprat terrcount if territor==1

logit cow5yrwi mixed  caprat terrcount if territor==1 & rival==1

logit cowwar mixed caprat terrcount if territor==1

logit cowwar mixed  caprat terrcount if territor==1 & rival==1


*Penalized Logits from Appendix

*Appendix Table 2

firthlogit cow5yrwi mixed terrXmixed territor terrXdem jtdem caprat terrcount rival

firthlogit cow5yrwi mixed terrXmixed territor terrXdem jtdem caprat terrcount if rival==1

firthlogit cowwar mixed terrXmixed territor terrXdem jtdem caprat terrcount rival

firthlogit cowwar mixed terrXmixed territor terrXdem jtdem caprat terrcount if rival==1

*Appendix Table 3


firthlogit cow5yrwi mixed jtdem caprat terrcount rival if territor==1

firthlogit cow5yrwi mixed  jtdem caprat terrcount if rival==1 & territor==1

firthlogit cowwar mixed  jtdem caprat terrcount rival if territor==1

firthlogit cowwar mixed  jtdem caprat terrcount if rival==1 & territor==1



clear

use "Wright_Diehl_2014_JCR_1946-1999.dta"



*Table 3
tab demboss cow5yrwi  if  wmixed!=. & territor==1 & wjdem !=. & demboss!=. & demjunta !=. & demmachine!=. & demstrong!=. & caprat!=. & terrcount!=. & rival !=., expected chi2

tab  demjunta  cow5yrwi if  wmixed!=. & territor==1 & wjdem !=. & demboss!=. & demjunta !=. & demmachine!=. & demstrong!=. & caprat!=. & terrcount!=. & rival !=., expected chi2

tab  demmachine cow5yrwi  if  wmixed!=. & territor==1 & wjdem !=. & demboss!=. & demjunta !=. & demmachine!=. & demstrong!=. & caprat!=. & terrcount!=. & rival !=., expected chi2

tab demstrong cow5yrwi  if  wmixed!=. & territor==1 & wjdem !=. & demboss!=. & demjunta !=. & demmachine!=. & demstrong!=. & caprat!=. & terrcount!=. & rival !=., expected chi2

tab wjdem cow5yrwi  if  wmixed!=. & territor==1 & wjdem !=. & demboss!=. & demjunta !=. & demmachine!=. & demstrong!=. & caprat!=. & terrcount!=. & rival !=., expected chi2

tab wmixed cow5yrwi  if  wmixed!=. & territor==1 & wjdem !=. & demboss!=. & demjunta !=. & demmachine!=. & demstrong!=. & caprat!=. & terrcount!=. & rival !=., expected chi2

tab jtauto  cow5yrwi if  wmixed!=. & territor==1 & wjdem!=. & demboss!=. & demjunta !=. & demmachine!=. & demstrong!=. & caprat!=. & terrcount!=. & rival !=., expected chi2


*Table 4

logit cow5yrwi  demboss demjunta demstrong   wmixed caprat terrcount rival  if territor==1 

logit cow5yrwi  demboss demjunta demstrong   wmixed caprat terrcount  if territor==1  & rival==1

logit cowwar  demboss demjunta demstrong   wmixed caprat  terrcount rival if territor==1 

logit cowwar  demboss demjunta demstrong   wmixed caprat  terrcount if territor==1  & rival==1




*Figure 2 Probabilities (and first differences in appendix) 

  
estsimp logit cow5yrwi  demboss demjunta demstrong   wmixed caprat terrcount if territor==1  & rival==1 

setx demboss 0 demjunta 0 demstrong 0 wmixed 0 caprat (mean) terrcount (mean)
simqi, pr level(90)

setx demboss 0 demjunta 0 demstrong 0 wmixed 1 caprat (mean) terrcount (mean)
simqi, pr level(90)

setx demboss 1 demjunta 0 demstrong 0 wmixed 1 caprat (mean)  terrcount (mean)
simqi, pr level(90)

setx demboss 0 demjunta 1 demstrong 0 wmixed 1 caprat (mean) terrcount (mean)
simqi, pr level(90)

setx demboss 0 demjunta 0 demstrong 1 wmixed 1 caprat (mean) terrcount (mean)
simqi, pr level(90)


*first differences (Figure 2 in Appendix)
setx demboss 0 demjunta 0 demstrong 0 wmixed 0 caprat (mean) terrcount (mean)
simqi, fd(prval(1))  changex(demstrong 0 1) level(90)

setx demboss 0 demjunta 0 demstrong 0 wmixed 0 caprat (mean) terrcount (mean)
simqi, fd(prval(1))  changex(demboss 0 1) level(90)

setx demboss 0 demjunta 0 demstrong 0 wmixed 0 caprat (mean) terrcount (mean)
simqi, fd(prval(1))  changex(demjunta 0 1) level(90)

setx demboss 0 demjunta 0 demstrong 0 wmixed 0 caprat (mean) terrcount (mean)
simqi, fd(prval(1))  changex(wmixed 0 1) level(90)


drop b1 b2 b3 b4 b5 b6 b7



*Appendix Table 4

firthlogit cow5yrwi territor  terrXdemboss  terrXdemjunta terrXdemstrong terrXdemmachine terrXwjdem  demboss demjunta demstrong demmachine wjdem wmixed caprat   terrcount rival

firthlogit cowwar territor  terrXdemboss  terrXdemjunta terrXdemstrong terrXdemmachine terrXwjdem  demboss demjunta demstrong demmachine wjdem wmixed caprat   terrcount rival


*Appendix Table 5

firthlogit cow5yrwi  demboss demjunta demstrong demmachine wjdem   wmixed caprat  terrcount rival if territor==1  

firthlogit cow5yrwi  demboss demjunta demstrong  demmachine wjdem  wmixed caprat  terrcount if territor==1 & rival==1, 

firthlogit cowwar  demboss demjunta demstrong  demmachine wjdem  wmixed caprat  terrcount rival if territor==1  

firthlogit cowwar  demboss demjunta demstrong demmachine wjdem   wmixed caprat  terrcount if territor==1 &  rival==1, 
